package com.sofwin.ruoyi.scyffinal.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.sofwin.ruoyi.scyffinal.pojo.RiskManagementMeasures;
import com.sofwin.ruoyi.scyffinal.service.RMMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/measures")
public class RMMController extends BaseController {

    @Autowired
    private RMMService rmmService;

    /**
     * 获取风险管控措施列表
     * @param riskManagementMeasures 前端获取对象  通过条件查询列表
     * @return
     */
    @RequiresPermissions("system:measures:list")
    @GetMapping("/list")
    public TableDataInfo list(RiskManagementMeasures riskManagementMeasures){
        startPage();
        List<RiskManagementMeasures> list = rmmService.SelectRiskManagementMeasuresList(riskManagementMeasures);
        return getDataTable(list);
    }

    /**
     * 新增风险管控措施
     * @param riskManagementMeasures 从前端获取新增的对象
     * @return
     */
    @RequiresPermissions("system:measures:add")
    @Log(title = "风险管理措施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody RiskManagementMeasures riskManagementMeasures){

        return toAjax(rmmService.insertRiskManagementMeasures(riskManagementMeasures));
    }

    /**
     * 删除风险管控对象
     * @param ids 从前端获取的 id集合
     * @return
     */
    @RequiresPermissions("system:measures:remove")
    @Log(title = "风险管理措施", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable Long [] ids){
        return toAjax(rmmService.deleteRiskManagementMeasuresByIds(ids));
    }

    /**
     * 编辑风险管控对象
     * @param riskManagementMeasures 通过id的获取对象 从前端传过来
     * @return
     */
    @RequiresPermissions("system:measures:edit")
    @Log(title = "风险管理措施", businessType = BusinessType.UPDATE)    @PutMapping()
    public AjaxResult edit(@Validated @RequestBody RiskManagementMeasures riskManagementMeasures){
        return toAjax(rmmService.updateRiskManagementMeasures(riskManagementMeasures));
    }

    /**
     * 通过id获取对象
     * @param id 从前端传来的id
     * @return
     */
    @RequiresPermissions("system:measures:query")
    @GetMapping("/{id}")
    public AjaxResult query(@PathVariable Long id){
        return success(rmmService.selectRiskManagementMeasuresById(id));
    }

}
